class Solution(object):
    def minMoves(self, target, maxDoubles):
        ans = 0
        while target > 0 and maxDoubles > 0:
            if target % 2:
                ans += 1
                target -= 1
            else:
                ans += 1
                target //= 2
                maxDoubles -= 1
        return ans + target - 1
